package threadlocal;

/**
 * Created by chinalin on 2017/3/22.
 */
public class SequenceB implements Sequence {

    private static ThreadLocal<Integer> numberContainer = new ThreadLocal<Integer>(){
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };

    @Override
    public int getNumber() {
        numberContainer.set(numberContainer.get() + 1);
        return numberContainer.get() ;
    }

    public static void main(String[] args) {
        Sequence sequence = new SequenceB() ;
        CliecntThread thread1 = new CliecntThread(sequence) ;
        CliecntThread thread2 = new CliecntThread(sequence) ;
        CliecntThread thread3 = new CliecntThread(sequence) ;

        thread1.start();
        thread2.start();
        thread3.start();
    }

}
